<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <link rel="stylesheet" href="css/register.css">
    <script src="js/jquery-3.6.0.js"></script>
    <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.css">
</head>
<script>
    $(function () {
        const REGISTER_URL="http://localhost:8080/user/register";
        $("#register").click(function () {
            let $username = $("#username").val();
            let $password = $("#password").val();
            let $rePassword = $("#passwordTest").val();
            let param ={
                username:$username,
                password:$password,
                rePassword:$rePassword
            };
            if($username === null || $username === ""){
                alert("用户名不能为空")
            }else if ($password === null || $password === ""){
                alert("密码不能为空")
            }else if ($rePassword === null || $rePassword === ""){
                alert("确认密码不能为空")
            }else if(!($password === $rePassword)){
                alert("两次密码不一致")
            }else {
                $.get(REGISTER_URL,param,function (result) {
                    if(result.status === 200){
                        alert("注册成功")
                        location.href="login.html"
                    }else if(result.status === -4){
                        alert("注册失败")
                    }

                })
            }
        })
    })
</script>

<body style="background: url('images/BG1.jpg') ;background-repeat:no-repeat ;background-size:100% 100% ;background-attachment: fixed ;">
<div id="register-box">
    <h1>注 册</h1>
    <div class="form">
        <div class="item">
            <i class="fa fa-user" aria-hidden="true"></i>
            <label for="username"></label>
            <input id="username" type="text" placeholder="请输入用户名">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="password"></label>
            <input id="password" type="password" placeholder="请输入密码">
        </div>

        <div class="item">
            <i class="fa fa-key" aria-hidden="true"></i>
            <label for="passwordTest"></label>
            <input id="passwordTest" type="password" placeholder="请再次输入密码">
        </div>

        <div class="item" style="color: whitesmoke">
            已经有了账户？<a href="login.html" class="txt2">立即登录</a>
        </div>
    </div>
    <button id="register">立 即 注 册</button>
</div>
</body>
</html>